﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class TankMove : MonoBehaviour {
    private float speeds = 10f;       //
    private float AngularSpeed = 30f;//
    public float number = 1f;        //
    private Rigidbody rigi;

    public AudioClip tankidle;
    public AudioClip tankdrivine;
    private AudioSource audio;

	void Start () {
        rigi =this.GetComponent<Rigidbody>();
        audio = this.GetComponent<AudioSource>();
	}

    void FixedUpdate() {
        float v = Input.GetAxis("VerticalPlay"+number);
        rigi.velocity = transform.forward * v * speeds;
        float h = Input.GetAxis("HorizontalPlay"+number);
        rigi.angularVelocity = transform.up * h * AngularSpeed;

        if (Mathf.Abs(h) > 0.1 || Mathf.Abs(v) > 0.1)
        {
            audio.clip = tankdrivine;
            if(audio.isPlaying == false)
            audio.Play();
        }
        else {
            audio.clip = tankidle;
            if (audio.isPlaying == false)
            audio.Play();
        }
    }
}
